<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function index(){
        $this->display("login");
    }
	public function check(){
		$account=I('post.account_name');
		$password=I('post.account_password');
		/*$data = array(
			'status' => true //true或false
			'count' =>		//状态码
			'data'  =>      //数据或错误提示
		);*/
		if ( $account == '' || $password == ''){
			$data = array(
			'status' => false, //true或false
			//'count' =>0,		//状态码
			'data'  =>"参数错误！"      //数据或错误提示
			);
			$this->ajaxReturn($data);
			return;
		}
		$Account = M ('Account');
		$password = md5($password);
		$ret = $Account->where("account_name='{$account}' and account_password='{$password}'")->find();
		//echo $Account->getLastSql();
		//exit;
		if( $ret == false){
			$data = array(
				'status' => false, //true或false
				//'count' =>0,		//状态码
				'data'  =>"用户名与密码不匹配"      //数据或错误提示
				);
			$this->ajaxReturn($data);
			return;
		}
		$_SESSION['UID'] = $ret['account_id'];
		$_SESSION['ACCOUNT'] = $account;
		$data = array(
				'status' =>true, //true或false
				//'count' =>0,		//状态码
				'data'  =>"登录成功"      //数据或错误提示
				);
		$this->ajaxReturn($data);
	}
	public function loginout(){
		$_SESSION['UID'] = '';
		$_SESSION['ACCOUNT'] = '';
		$this->redirect("Admin/Login/login");
	}
}//
